<?php

// Gallery plugin by Sergi March

require_once 'classes/LightPressPlugin.php';

class Gallery extends LightPressPlugin {
    
    var $constructor_args = array(
        'url'=>'URL for loading the Gallery2 external reference (plugin Image Block from Gallery2)');
    var $default_context = LP_CONTEXT_INDEX;
    var $description = 'Show a random image from Gallery2';
    
    var $active = true;
    var $hooks = array('sidebar');
    var $url;

    function Gallery(&$frontend, $args, $dummy_run=false) {
        $this->LightPressPlugin($frontend, $args, $dummy_run);
    }
    
    function run($hook, &$payload) {
        $url = $this->url;
        //$url = 'http://fotos.maladeta.com/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title&g2_itemId=22318';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $store = curl_exec ($ch);
        $xml = curl_exec ($ch);
        curl_close ($ch);
        $tpl =& $this->_frontend->tpl;
        $tpl->setFile('plugin_gallery', 'plugins/gallery.xml');        
        $tpl->setVar('plugin_gallery_message', $xml);
        $tpl->parse('PLUGIN_GALLERY', 'plugin_gallery');
    }
    
    function install() {
        if (!extension_loaded('curl'))
            return "You need the PHP curl extension to use this plugin";
    }
    
}

?>
